// import HansTabbar from '@/components/common/hans-tabbar/hans-tabbar.vue'
import { mapState, mapMutations  } from 'vuex'
import { getCurrRoute } from '@/utils/util.js'

export default {
	components: {
		// HansTabbar
	},
	computed: {
		...mapState(['tabCurrent', 'tabBarList']),
	},
	onShow() {
		let route = getCurrRoute()
		let routePath = route.substring(0, route.indexOf('?'))
		this.getTabIndex(routePath)
	},
	methods: {
		...mapMutations(['setTabCurrent']),
		tabChange(index) {
			const page = this.tabBarList[index]
			
			this.setTabCurrent(index)
			if(page?.web) {

				uni.navigateTo({
					url: page.pagePath
				});
				return
			}
			
			uni.redirectTo({
				url: page.pagePath
			})
		},
		getTabIndex(routePath) {
			const curIndex = this.tabBarList.findIndex(tab => tab.pagePath == routePath) ?? 0
			this.setTabCurrent(curIndex);
		}
	}
}
